<template>
	<view class="setting">
		<view class="ucenter">
			<view class="menu-lists">
				<view class="item">
					<view class="icon">
						<view class="iconfont icon-08"></view>
					</view>
					<view class="name muti">
						<view class="main-name">钱包名称</view>
						<view class="sub-name">
							<view class="text">{{user.wallet_name}}</view>
							<view class="icon">
								<view class="iconfont icon-jiantou"></view>
							</view>
						</view>
					</view>
				</view>
				<view class="item" @click="confirmDialog()">
					<view class="icon">
						<view class="iconfont icon-yuechi1"></view>
					</view>
					<view class="name muti">
						<view class="main-name">导出私钥</view>
						<view class="sub-name">
							<view class="icon">
								<view class="iconfont icon-jiantou"></view>
							</view>
						</view>
					</view>
				</view>
				<view class="item" @click="logout()">
					<view class="icon">
						<view class="iconfont icon-tuichu"></view>
					</view>
					<view class="name muti">
						<view class="main-name">退出钱包</view>
						<view class="sub-name">
							<view class="icon">
								<view class="iconfont icon-jiantou"></view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<uni-popup id="dialogInput" ref="dialogInput" type="dialog">
			<uni-popup-dialog :password="true" mode="input" title="请输入钱包密码" value="" placeholder="请输入密码"
				@confirm="dialogInputConfirm"></uni-popup-dialog>
		</uni-popup>
	</view>
</template>

<script>
	import api from "@/utils/api/wallet/index.js"
	import util from '@/common/util.js'
	export default {
		data() {
			return {
				user: {
					wallet_name: ""
				},
			}
		},
		onLoad() {
			this.user = uni.getStorageSync("user")
			console.log(this.user)
		},
		methods: {
			exportPrivateKey() {
				uni.navigateTo({
					url: "../wallet/private-key"
				})
			},
			logout() {
				uni.reLaunch({
					url: "../../wallet/create-wallet"
				})
			},
			/**
			 * 打开提交信息
			 */
			confirmDialog() {
				this.$refs.dialogInput.open()
			},
			/**
			 * 输入对话框的确定事件
			 */
			async dialogInputConfirm(done, val) {
				uni.showLoading({
					title: '验证中'
				})
				console.log(val);
				this.value = val
				let post = {
					password: this.value
				};
				let res = await api.getPrivateKey(post)
				uni.hideLoading()
				done()

				if (res.status == 1) {
					uni.navigateTo({
						url: "../wallet/private-key?privateKey=" + res.data
					})
				}


			},
			/**
			 * 对话框取消按钮
			 */
			dialogClose(done) {
				this.msgType = 'info'
				this.message = '点击了对话框的取消按钮'
				this.$refs.popupMessage.open()
				// 需要执行 done 才能关闭对话框
				done()
			},
		}
	}
</script>

<style lang="scss">
	view {
		display: flex;
		flex-direction: column;
		box-sizing: border-box;
	}
</style>
